
//
//  DepositSegmentController.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2020/3/16.
//  Copyright © 2020 zwb. All rights reserved.
//

import UIKit

class ZyaDepositSegmentVC: DQBaseHomeViewController,UISearchBarDelegate {
    
    var vc1:ZyaDepositListVC!
    var vc2:ZyaDepositListVC!
    var vc3:ZyaDepositListVC!
    var vc4:ZyaDepositListVC!
    var searchTitle = ""
    private var searchBar:UISearchBar?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.DQColer = Theme.primaryColor()
        self.setSearchBar()
        
        vc1 = ZyaDepositListVC()
        vc1.title = "待审核"
        vc1.auditMark = "0"
        
        vc2 = ZyaDepositListVC()
        vc2.title = "已审核"
        vc2.auditMark = "1"
        vc3 = ZyaDepositListVC()
        vc3.title = "退款中"
        vc3.auditMark = "2"
        vc4 = ZyaDepositListVC()
        vc4.title = "已退款"
        vc4.auditMark = "3"
        
        self.addChild(vc1)
        self.addChild(vc2)
        self.addChild(vc3)
        self.addChild(vc4)
    }
    
    
    func setSearchBar () {
        searchBar = UISearchBar(frame:CGRect(x:0,y:0,width:KSGlobal.screenW * 0.65,height:40))
        let toolbar = UIToolbar()
        toolbar.barStyle = UIBarStyle.default
        toolbar.sizeToFit()
        let buttonflexible = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
        let buttonDone = UIBarButtonItem(title: "完成", style: UIBarButtonItem.Style.done, target: self, action: #selector(doneClickss))
        buttonDone.tintColor = UIColor.black
        toolbar.setItems([buttonflexible, buttonDone], animated: true)
        
        searchBar!.inputAccessoryView = toolbar
        
        if #available(iOS 13, *) {
            
            searchBar!.searchTextField.backgroundColor = .white
        } else {
            
        }
        
        searchBar!.text = searchTitle
        searchBar!.placeholder = "搜索付款信息"
        searchBar!.delegate = self
        let searchView = UIView(frame:CGRect(x:0,y:0,width:KSGlobal.screenW * 0.65 ,height:40))
        searchView.addSubview(searchBar!)
        self.navigationItem.titleView = searchView
        
        
    }
    @objc func doneClickss() {
        self.searchBar!.resignFirstResponder()
    }
    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
        searchBar.resignFirstResponder()
        
    }
    func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
        searchTitle = searchBar.text.unwrap
        self.vc1.searchTitle = searchTitle
        self.vc1.tableView.mj_header?.beginRefreshing()
        self.vc2.searchTitle = searchTitle
        self.vc2.tableView.mj_header?.beginRefreshing()
        self.vc3.searchTitle = searchTitle
        self.vc3.tableView.mj_header?.beginRefreshing()
        self.vc4.searchTitle = searchTitle
        self.vc4.tableView.mj_header?.beginRefreshing()
    }
    
    
}
